package com.ruoyi.member.controller;

import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.member.domain.BmInorderlist;
import com.ruoyi.member.domain.BmWarehouse;
import com.ruoyi.member.domain.MyMap;
import com.ruoyi.member.job.MyMapEnable;
import com.ruoyi.member.service.IBmInorderlistService;
import com.ruoyi.member.service.ISellerMyOrderService;
import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author huang
 * @Date 2023/8/14 9:04
 * @PackageName: com.ruoyi.member.controller
 * @ClassName: SellerMyOrderController
 * @Description:
 * @Version 1.0
 */

@RestController
@RequestMapping("/seller/myOrder")
public class SellerMyOrderController {

    @Autowired
    private ISellerMyOrderService myOrderService;
    @Autowired
    private IBmInorderlistService iBmInorderlistService;
    @Autowired
    private IBmInorderlistService bmInorderlistService;

    @GetMapping("/getOrderList/{orderStepFlag}")
    public List<BmInorderlist> getOrderList(@PathVariable("orderStepFlag") int orderStepFlag) {
        List<BmInorderlist> orderList = myOrderService.getOrderList(orderStepFlag);
        return orderList;
    }

    @PutMapping("/cancelOrder")
    public boolean cancelOrder(String orderCode) {
        boolean b = myOrderService.cancelOrder(orderCode);
        return b;
    }

    @PutMapping("/updateWarehouseUserStatus")
    public boolean updateWarehouseUserStatus(@RequestBody BmWarehouse bmWarehouse) {
        myOrderService.changeWarehouseStatus(bmWarehouse);
        return true;
    }

    @PutMapping("/updateWuliuUserStatus")
    public boolean updateWuliuUserStatus(@RequestBody BmWarehouse bmWarehouse) {
        myOrderService.changeWuliuStatus(bmWarehouse);
        return true;
    }

    @GetMapping("/setMap")
    public boolean setMap(MyMap map) {
        boolean b = myOrderService.setMap(map);
        return true;
    }

    @GetMapping("/getMap")
    public boolean getMap() {
        try {
            MyMapEnable.enable();
        } catch (SchedulerException e) {
            throw new RuntimeException(e);
        }
        return true;
    }

    @PostMapping ("/dispatch")
    public boolean one(@RequestBody BmInorderlist bmInorderlist) {
        myOrderService.dispatch(bmInorderlist);
        return true;
    }
    @PostMapping("/selectInorderList")
    public List<Map<String,Object>> selectInorderList(@RequestBody Map<String,Object> map){
        List<Map<String, Object>> list = iBmInorderlistService.selectInorderList(map);
        return list;
    }

    @PostMapping("/selectInorderGoodsList")
    public List<Map<String,Object>> selectInorderGoodsList(@RequestBody Map<String,Object> map){
        List<Map<String, Object>> list = iBmInorderlistService.selectInorderGoodsList(map);
        return list;
    }

    @GetMapping(value = "/orderStepToFour/{orderCode}")
    public AjaxResult updateOrderStepToFour(@PathVariable("orderCode") String orderCode)
    {
        bmInorderlistService.updateOrderStepToFour(orderCode);
        return AjaxResult.success();
    }

    @GetMapping("/getOrderDetail/{orderCode}")
    public AjaxResult getOrderDetail(@PathVariable("orderCode") String orderCode) {
        BmInorderlist orderDetail = myOrderService.getOrderDetail(orderCode);
        return AjaxResult.success(orderDetail);
    }
}
